#include <iostream>
#include <unordered_map>
#include <cmath>

bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int closest_prime_number(std::string s) {
    std::unordered_map<std::string, int> number_words = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    try {
        std::string num_str;
        for (const std::string word : s) {
            num_str += std::to_string(number_words[word]);
        }
        int num = std::stoi(num_str);

        if (num >= 100 && num <= 999) {
            int lower = num;
            int upper = num;

            while (!is_prime(lower) && !is_prime(upper)) {
                --lower;
                ++upper;
            }

            while (!is_prime(lower)) {
                --lower;
            }

            while (!is_prime(upper)) {
                ++upper;
            }

            if (is_prime(lower)) {
                return lower;
            } else {
                return upper;
            }
        } else {
            return -1; // Wrong input
        }
    } catch (...) {
        return -1; // Wrong input
    }
}

int main() {
    std::string input_str;
    std::cout << "Enter three numbers in English separated by spaces: ";
    std::getline(std::cin, input_str);

    int result = closest_prime_number(input_str);
    if (result == -1) {
        std::cout << "Wrong input" << std::endl;
    } else {
        std::cout << "Closest prime number: " << result << std::endl;
    }

    return 0;
}